//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.sys;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.ShopDprDao;
import com.aidong.model.wills.ShopDpr;
import com.aidong.model.wills.ShopDprPK;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"sysShopDpr"})
public class SysShopDprController extends BaseController {
    @Resource
    ShopDprDao shopDprDao;

    public SysShopDprController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("sys/shopdpr/list")).addObject("shopName", this.getTypeList("shopName"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "period",required = false) String period, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "ShopCode", shopCode);
        cd.eq("period", period);
        this.shopDprDao.queryPageList(pg, cd, (new OrderSet()).asc("ShopCode"));
        ModelAndView mv = new ModelAndView("sys/shopdpr/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        ShopDpr shopDpr = new ShopDpr();
        ModelAndView mv = new ModelAndView("sys/shopdpr/edit");
        mv.addObject("shopDpr", shopDpr);
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("shopDpr") ShopDpr shopDpr) {
        if(this.chkNull(shopDpr.getShopCode())) {
            return this.getResult(false, "请输入门店");
        } else if(this.chkNull(shopDpr.getPeriod())) {
            return this.getResult(false, "请输入DPR月度");
        } else {
            shopDpr.setCreateUser(this.getLoginUserCode());
            shopDpr.setCreateTime(new Date());
            shopDpr.setUpdateTime(new Date());

            try {
                this.shopDprDao.add(shopDpr);
                this.addUserLog("DPR月度目标设置", "门店:" + shopDpr.getShopCode() + ",月度:" + shopDpr.getPeriod());
            } catch (Exception var3) {
                this.log.error("add shopDpr", var3);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "保存完成");
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("shopCode") String shopCode, @RequestParam("period") String period) {
        ShopDprPK pk = new ShopDprPK();
        pk.setShopCode(shopCode);
        pk.setPeriod(period);
        ShopDpr shopDpr = (ShopDpr)this.shopDprDao.getById(pk);
        if(shopDpr == null) {
            return this.showAlert("没有这个记录");
        } else {
            ModelAndView mv = new ModelAndView("sys/shopdpr/edit");
            mv.addObject("shopDpr", shopDpr);
            mv.addObject("shopName", this.getTypeList("shopName"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("shopDpr") ShopDpr shopDpr) {
        if(this.chkNull(shopDpr.getShopCode())) {
            return this.getResult(false, "请输入门店");
        } else if(this.chkNull(shopDpr.getPeriod())) {
            return this.getResult(false, "请输入DPR月度");
        } else {
            ShopDprPK pk = new ShopDprPK();
            pk.setShopCode(shopDpr.getShopCode());
            pk.setPeriod(shopDpr.getPeriod());
            ShopDpr shopDpr1 = (ShopDpr)this.shopDprDao.getById(pk);
            if(shopDpr1 == null) {
                return this.getResult(false, "没有这个记录");
            } else {
                shopDpr1.setCardSaleTarget(shopDpr.getCardSaleTarget());
                shopDpr1.setNewMemberTarget(shopDpr.getNewMemberTarget());
                shopDpr1.setPiTarget(shopDpr.getPiTarget());
                shopDpr1.setPiBeautyTarget(shopDpr.getPiBeautyTarget());
                shopDpr1.setDeptmanager(shopDpr.getPtmanager());
                shopDpr1.setGuesttarget(shopDpr.getGuesttarget());
                shopDpr1.setOtherSaleTarget(shopDpr.getOtherSaleTarget());
                shopDpr1.setProductSaleTarget(shopDpr.getProductSaleTarget());
                shopDpr1.setGncSaleTarget(shopDpr.getGncSaleTarget());
                shopDpr1.setCosmeticTarget(shopDpr.getCosmeticTarget());
                shopDpr1.setUpdateTime(new Date());

                try {
                    this.shopDprDao.update(shopDpr1);
                    this.addUserLog("修改DPR月度目标设置", "门店:" + shopDpr1.getShopCode() + ",月度:" + shopDpr1.getPeriod());
                } catch (Exception var5) {
                    this.log.error("edit shopDpr", var5);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("shopCode") String shopCode, @RequestParam("period") String period) {
        ShopDprPK pk = new ShopDprPK();
        pk.setShopCode(shopCode);
        pk.setPeriod(period);
        ShopDpr shopDpr = (ShopDpr)this.shopDprDao.getById(pk);
        if(shopDpr == null) {
            return this.getResult(false, "没有这个记录");
        } else {
            try {
                this.shopDprDao.delete(shopDpr);
                this.addUserLog("删除DPR月度目标设置", "门店:" + shopCode + ",月度:" + period);
            } catch (Exception var6) {
                this.log.error("del shopDpr", var6);
                return this.getResult(false, "删除发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }

    @RequestMapping({"copy"})
    public ModelAndView copy(@RequestParam("shopCode") String shopCode, @RequestParam("period") String period) {
        ShopDprPK pk = new ShopDprPK();
        pk.setShopCode(shopCode);
        pk.setPeriod(period);
        ShopDpr shopDpr = (ShopDpr)this.shopDprDao.getById(pk);
        if(shopDpr == null) {
            return this.showAlert("没有这个记录");
        } else {
            ModelAndView mv = new ModelAndView("sys/shopdpr/edit");
            mv.addObject("shopDpr", shopDpr);
            mv.addObject("shopName", this.getTypeList("shopName"));
            mv.addObject("_oper", "copy");
            return mv;
        }
    }

    @RequestMapping({"_copy"})
    @ResponseBody
    public String _copy(@ModelAttribute("shopDpr") ShopDpr shopDpr) {
        if(this.chkNull(shopDpr.getShopCode())) {
            return this.getResult(false, "请输入门店");
        } else if(this.chkNull(shopDpr.getPeriod())) {
            return this.getResult(false, "请输入DPR月度");
        } else {
            shopDpr.setCreateUser(this.getLoginUserCode());
            shopDpr.setCreateTime(new Date());
            shopDpr.setUpdateTime(new Date());

            try {
                this.shopDprDao.add(shopDpr);
                this.addUserLog("DPR月度目标设置", "门店:" + shopDpr.getShopCode() + ",月度:" + shopDpr.getPeriod());
            } catch (Exception var3) {
                this.log.error("add shopDpr", var3);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "保存完成");
        }
    }
}
